<?php
/**
 * 产品管理
 * @author cjli
 *
 */
class UserSizeAction extends AdminAction
{
	public function _initialize()
	{
		parent::_initialize();
	}

	//尺码表
	public function size_list()
	{
		$user_size = D('user_size');
		$where = array();
		$sizeCount = $user_size->where($where)->count();

		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($sizeCount, 20);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);

		$user_size->where($where);
		$user_size->limit($Page->firstRow, $Page->listRows);
		$sizeList = $user_size->select();
		$this->assign('sizeList', $sizeList);
		$this->assign('search', $_REQUEST);
		
		$this->display('size_list');
	}
	
	//添加尺码
	public function size_add()
	{
		if(isset($_POST['dosubmit']))
		{
			$post = $_POST;
			$user_size = D('user_size');
					
			$data = array(
				'height' 			=> $post['height'],
				'weight' 			=> $post['weight'],
				'height2' 			=> $post['height2'],
				'weight2' 			=> $post['weight2'],
				'circumference' 	=> $post['circumference'],
				'waistline' 		=> $post['waistline'],
				'hipline' 			=> $post['hipline'],
				'shoulder' 			=> $post['shoulder'],
				'forepart_length' 	=> $post['forepart_length'],
				'outside_sleeve' 	=> $post['outside_sleeve'],
				'time' 				=> time(),
			);
			$user_size->add($data);
			$this->success('尺码添加成功！', U('user_size/size_list'));
		}else{
			$this->display('size_from');
		}
	}
	
	//编辑尺码
	public function size_edit()
	{	
		$pid = intval($_REQUEST['id']);
		if(isset($_POST['dosubmit']))
		{
			if(!$pid){
				$this->error('尺码编辑失败，请重新输入');
			}
			
			$post = $_POST;
			$user_size = D('user_size');
					
			$data = array(
				'height' 			=> $post['height'],
				'weight' 			=> $post['weight'],
				'height2' 			=> $post['height2'],
				'weight2' 			=> $post['weight2'],
				'circumference' 	=> $post['circumference'],
				'waistline' 		=> $post['waistline'],
				'hipline' 			=> $post['hipline'],
				'shoulder' 			=> $post['shoulder'],
				'forepart_length' 	=> $post['forepart_length'],
				'outside_sleeve' 	=> $post['outside_sleeve'],
			);

			$user_size->where(array('id' => $pid))->save($data);
			
			
			$this->success('尺码编辑成功！', U('user_size/size_list'));
		
		}else{
		
			$user_size = D('user_size');
			$size = $user_size->find($pid);
		
			$this->assign('size', $size);
			$this->display('size_from');
		}
	}
	
	//删除尺码
	public function size_delete()
	{
		$pid = intval($_GET['id']);
		$user_size = D('user_size');
		$size = $user_size->find($pid);
		if(!$size){
			$this->error('尺码不存在！', U('user_size/size_list'));
		}

		$user_size->where('id='.$pid)->delete();
		$this->success('尺码删除成功！', U('user_size/size_list'));
	}
}